package com.tiansheng.view.dialog;

import java.util.List;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import com.tiansheng.model.entity.Custom;
import com.tiansheng.model.entity.CustomDao;
import com.tiansheng.model.entity.Order;
import com.tiansheng.model.entity.OrderDao;
import com.tiansheng.model.entity.OrderProductRelation;
import com.tiansheng.model.entity.OrderProductRelationDao;
import com.tiansheng.model.entity.Product;
import com.tiansheng.model.entity.ProductDao;
import com.tiansheng.model.entity.Settings;
import com.tiansheng.model.entity.SettingsDao;
import com.tiansheng.view.tablemodel.OrderProductModel;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class OrderDetailDialog extends javax.swing.JDialog {
	private JLabel jLabel1;
	private JLabel jLabel2;
	private JLabel customLabel;
	private JScrollPane jScrollPane1;
	private JTable orderDetailTable;
	private JLabel orderNoLabel;
	private OrderProductModel optm;

	/**
	* Auto-generated main method to display this JDialog
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				OrderDetailDialog inst = new OrderDetailDialog(frame);
				inst.setVisible(true);
			}
		});
	}
	
	public OrderDetailDialog(JFrame frame) {
		super(frame);
		initGUI();
	}
	
	public OrderDetailDialog(JFrame frame, int orderId) {
		super(frame);
		initGUI();
		this.initData(orderId);
	}

	private void initGUI() {
		try {
			{
				getContentPane().setLayout(null);
				{
					jLabel1 = new JLabel();
					getContentPane().add(jLabel1);
					jLabel1.setText("\u8ba2\u5355\u53f7\uff1a");
					jLabel1.setBounds(19, 48, 75, 17);
				}
				{
					orderNoLabel = new JLabel();
					getContentPane().add(orderNoLabel);
					orderNoLabel.setText("\u8ba2\u5355\u53f7\u5185\u5bb9");
					orderNoLabel.setBounds(99, 48, 336, 17);
				}
				{
					jLabel2 = new JLabel();
					getContentPane().add(jLabel2);
					jLabel2.setText("\u5ba2\u6237\u540d\u79f0\uff1a");
					jLabel2.setBounds(19, 77, 75, 17);
				}
				{
					customLabel = new JLabel();
					getContentPane().add(customLabel);
					customLabel.setText("\u5ba2\u6237\u540d\u79f0\u5185\u5bb9");
					customLabel.setBounds(99, 77, 336, 17);
				}
				{
					jScrollPane1 = new JScrollPane();
					getContentPane().add(jScrollPane1);
					jScrollPane1.setBounds(7, 106, 572, 220);
					{
						optm = new OrderProductModel();
						orderDetailTable = new JTable();
						jScrollPane1.setViewportView(orderDetailTable);
						orderDetailTable.setModel(optm);
					}
				}
			}
			pack();
			this.setSize(600, 400);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	

	
	private void initData(int orderId) {
		try {
			Order o = OrderDao.getEntityById(orderId);
			this.orderNoLabel.setText(o.getOrderNo());
			Custom c = CustomDao.getCustomById(o.getCustomId());
			this.customLabel.setText(c.getCustomName());
			
			List<OrderProductRelation> oprList = OrderProductRelationDao.getOrderProductRelations(orderId);
			Vector v = new Vector();
			for(OrderProductRelation opr : oprList) {
				Vector row = new Vector();
				row.add("-");
				Product p = ProductDao.getEntityById(opr.getOprPK().getProductId());
				Settings color = SettingsDao.getEntityById(p.getProductColorId());
				row.add(color.getSettingsValue());
				row.add(p.getProductWidth());
				row.add(p.getProductWeight());
				row.add(opr.getProductTagedWeight());
				row.add(opr.getProductStock());
				row.add(opr.getProductNumber());
				row.add(opr.getProductNumberTotal());
				row.add(opr.getProductPrice());
				row.add(opr.getProductTotal());
				row.add(opr.getPs());
//				System.out.println(opr.getOprPK().getProductId());
//				System.out.println(opr.getProductNumber());
//				System.out.println(opr.getProductStock());
//				System.out.println(opr.getProductPrice());
//				System.out.println(opr.getProductTagedWeight());
//				System.out.println(opr.getProductTotal());
//				System.out.println(opr.getPs());
				v.add(row);
			}
			this.optm.setData(v);
		} catch (Exception e) {
//				e.printStackTrace();
		}
		
	}

}
